//
//  ActivityDetailCreaterself.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 16/9/2.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "ActivityDetailCreaterCell.h"
//#import "Masonry.h"

@interface ActivityDetailCreaterCell ()

//@property (nonatomic, strong) UIImageView *linebg;
//@property (nonatomic, strong) UILabel *lbName;
//@property (nonatomic, strong) UILabel *lbDateToDate;
//@property (nonatomic, strong) UILabel *lbNum;
@property (nonatomic, strong) UIImageView *activtyImageView;
@property (nonatomic, strong) UIImageView *iconImageView;

@end

@implementation ActivityDetailCreaterCell

+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    ActivityDetailCreaterCell* cell = [tableView dequeueReusableCellWithIdentifier:kActivityDetailCreaterCellIdentifier];
    
    if (cell == nil) {
        
        cell = [[ActivityDetailCreaterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kActivityDetailCreaterCellIdentifier];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setFrame:(CGRect)frame
{
    frame.size.width = [UIScreen mainScreen].bounds.size.width;
    [super setFrame:frame];
}

- (void)setupUI
{
    self.accessoryType = UITableViewCellAccessoryNone;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    CGRect cellBounds = CGRectMake(10, 155+43, CGRectGetWidth(self.bounds), 0.5);
    UIImageView *linebg = [[UIImageView alloc] initWithFrame:cellBounds];
    linebg.tag = 1000;
    linebg.image = [UIImage imageWithContentsOfFile:SEGPicName(@"common_line610px.png")];
    [self.contentView addSubview:linebg];
    
    self.activtyImageView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), 155)];
    [self.activtyImageView.layer setMasksToBounds:YES];
    self.activtyImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.activtyImageView.tag=1001;
    [self.contentView addSubview:self.activtyImageView];
    
    UILabel * lblName = [[UILabel alloc] initWithFrame:CGRectMake(20, 169, 200, 15)];
    lblName.font = [UIFont systemFontOfSize:FONT_LIST_AND_DETAIL_SIZE];
    lblName.textColor=kColor_2;
    lblName.tag = 1002;
    lblName.backgroundColor = [UIColor clearColor];
    lblName.text=@"发起人";
    [self.contentView addSubview:lblName];
    
    UILabel * nameLab = [[UILabel alloc] initWithFrame:CGRectMake(140, 169, 70, 15)];
    nameLab.font = [UIFont systemFontOfSize:FONT_LIST_AND_DETAIL_SIZE];
    nameLab.backgroundColor = [UIColor clearColor];
    nameLab.textColor=kColor_1;
    nameLab.tag=1003;
    
    [self.contentView addSubview:nameLab];
    
    self.iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.iconButton.frame=CGRectMake(100, 161, 32, 32);
    self.iconButton.tag=1004;
    self.iconButton.layer.masksToBounds = YES; 
    [self.iconButton seg_configWithRadius:2.f];
    //    [iconBtn addTarget:self action:@selector(btnSendMessageToFriendClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.iconButton];
    
    self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
    [self.iconImageView seg_configWithRadius:2.f];
    self.iconImageView.image = [UIImage imageWithContentsOfFile:@""];
    [self.iconButton addSubview:self.iconImageView];
}

- (void)setDataSource:(ActivityModel *)dataSource
{
    _dataSource = dataSource;
    
    self.activtyImageView.frame = CGRectMake(10, 10, 100, 60);
    
    [self.activtyImageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",kClientImageRootURL,dataSource.pic1]] placeholderImage:[UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_300_300")] options:SDWebImageLowPriority];
    
    CGRect cellBounds = CGRectMake(10, 155+43, CGRectGetWidth(self.bounds), 0.5);
    CGRect imageBounds = CGRectMake(0, 0, CGRectGetWidth(self.bounds), 155);
    CGRect lblNameBounds = CGRectMake(20, 169, 70, 15);
    CGRect nameBounds = CGRectMake(140, 169, 200, 15);
    CGRect iconBounds = CGRectMake(100, 161, 32, 32);
    
    UIImageView *linebg = (UIImageView *)[self.contentView viewWithTag:1000];
    UIImageView *imageBg = (UIImageView *)[self.contentView viewWithTag:1001];
    UILabel * lblName = (UILabel *)[self.contentView viewWithTag:1002];
    UILabel * nameLab = (UILabel *)[self.contentView viewWithTag:1003];
    UIButton *iconBtn = (UIButton *)[self.contentView viewWithTag:1004];
    
    if (dataSource.pic1) {
        linebg.frame = cellBounds;
        imageBg.frame =imageBounds;
        nameLab.frame = nameBounds;
        lblName.frame = lblNameBounds;
        iconBtn.frame = iconBounds;
        imageBg.hidden = NO;
    }else{
        imageBg.hidden = YES;
        linebg.frame = CGRectMake(0, 43, CGRectGetWidth(self.bounds), 0.5);
        //                imageBg.frame = CGRectMake(0, 0, 320, 155);
        lblName.frame = CGRectMake(20, 14, 70, 15);
        nameLab.frame = CGRectMake(140, 14, 200, 15);
        iconBtn.frame = CGRectMake(100, 7, 32, 32);
    }
    
    nameLab.text=dataSource.contact;
    
    if(![[dataSource.issuePerson stringValue] isEqualToString:@"0"])
    {
        if(dataSource.contactIcon.length > 0)
        {
            NSString *iconUrl = [NSString stringWithFormat:@"%@%@",kClientImageRootURL,dataSource.contactIcon];
            //            [SystemUtils saveServiceHeadImage:[NSURL URLWithString:iconUrl] aImageView:self.iconImageView defaultImage:@"headimg40"];
            [self.iconImageView setImageWithURL:[NSURL URLWithString:iconUrl] placeholderImage:[UIImage imageWithContentsOfFile:SEGPicName(@"headimg40")] options:SDWebImageLowPriority];
        }
        else{
            [iconBtn setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(@"headimg40")]
                               forState:UIControlStateNormal];
        }
        iconBtn.userInteractionEnabled = YES;
        
    }else{
        [iconBtn setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(@"headimg40")]
                           forState:UIControlStateNormal];
        iconBtn.userInteractionEnabled = NO;
    }
}

@end

